package com.atguigu.utils;

import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CyclicBarrier;

public class CyclicBarrierDemo1 {
    //正向计数方法CyclicBarrier
    public static void main(String[] args) {
        CyclicBarrier cyclicBarrier = new CyclicBarrier(5 , ()->{
            System.out.println("五行齐全");
        });

        for (int i = 1; i <= 5; i++) {
            int finalI = i;
            new Thread(()->{
                System.out.println(Thread.currentThread().getName() + " 号线程执行了... " + finalI);
                try {
                    cyclicBarrier.await();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }, String.valueOf(i)).start();
        }

    }
}
